<template>
    <div class="gly_style">
        <template>
            <a-table :columns="columns" :data-source="glydata">
                <template slot="roleVOList" slot-scope="roleVOList">
                    <span v-if="roleVOList[0]">{{ roleVOList[0].roleName || ''}}</span>
                    <span v-else></span>
                </template>
                <template slot="edit" slot-scope="userCode, item">
                    <a-popconfirm
                        title="确定要删除此管理员帐号吗?"
                        ok-text="删除"
                        cancel-text="取消"
                        @confirm="delglyconfirm(userCode)"
                        class="mr20"
                    >
                        <a href="javascript:;">删除</a>
                    </a-popconfirm>
                    <a href="javascript:;" @click="editgly(item)">编辑</a>
                </template>
            </a-table>
        </template>
    </div>
</template>

<script>
//管理员设置

export default {
   
    data() {
        return {
           
            //管理员管理
            glydata: [],
            // glyvisible: false,
            editglyflag: false,
            updategly: "",
            // 人员编辑或者新增人员信息
            userOprInfo: {
                userCode: "",
                userPassword: "",
                userMobile: "",
                userRealName: "",
                userEmail: "",
                addFlag: "",
                roleCode: "",
            },
            columns: [
                {
                    title: "账号",
                    dataIndex: "userCode",
                    key: "userCode",
                },
                {
                    title: "密码",
                    dataIndex: "userPassword",
                    key: "userPassword",
                },
                {
                    title: "姓名",
                    dataIndex: "userRealName",
                    key: "userRealName",
                },
                {
                    title: "邮箱",
                    dataIndex: "userEmail",
                    key: "userEmail",
                },
                {
                    title: "电话",
                    dataIndex: "userMobile",
                    key: "userMobile",
                },
                {
                    title: "权限",
                    dataIndex: "roleVOList",
                    key: "roleVOList",
                    scopedSlots: { customRender: "roleVOList" },
                },
                {
                    title: "操作",
                    dataIndex: "userCode",
                    key: "edit",
                    scopedSlots: {
                        customRender: "edit",
                    },
                },
            ],

           

           
            glyrules: {
                //管理员管理
                userCode: {
                    required: true,
                    message: "账号不能为空",
                },
                userPassword: {
                    required: true,
                    message: "密码不能为空",
                },
                userRealName: {
                    required: true,
                    message: "姓名不能为空",
                },
                userMobile: {
                    required: true,
                    message: "电话不能为空",
                },
                userEmail: {
                    required: true,
                    message: "邮箱不能为空",
                },
                roleCode: {
                    required: true,
                    message: "权限范围不能为空",
                },
            },
           
        };
    },
    
    mounted() {
        //管理员管理
        this.getOwerUserInfo();

   
    },
    methods: {
        //管理员管理
        editgly(item) {
          
            this.$emit('editgly',item);
        },
        delglyconfirm(glydelete) {
            this.glydelete(glydelete);
        },
        glydelete(userCode) {
            this.$post("/exter/manage/delUserOprInfo", {
                userCode: userCode,
            }).then((result) => {
                console.log(result);
                this.getOwerUserInfo();
            });
        },
        getOwerUserInfo() {
            this.$post("/exter/manage/getOwerUserInfo", {}).then((result) => {
                console.log(result);
                this.glydata = result.buss;
            });
        },
        handleDptUserSavegly() {
            // 更新还是新增1 修改0
            this.$refs["glyruleForm"].validate((valid) => {
                if (valid) {
                    if (this.updategly) {
                        this.userOprInfo.addFlag = 0;
                    } else {
                        this.userOprInfo.addFlag = 1;
                    }

                    this.$post(
                        "/exter/manage/addUserOprInfo",
                        this.userOprInfo
                    ).then((result) => {
                        console.log(result);
                        // this.glyvisible = false;
                        this.userOprInfo = {
                            userCode: "",
                            userPassword: "",
                            userMobile: "",
                            userRealName: "",
                            userEmail: "",
                            addFlag: "",
                            roleCode: "",
                        };
                        this.updategly = "";
                        this.editglyflag = false;
                        this.getOwerUserInfo();
                    });
                }
            });
        },
  
    },
  
};
</script>

<style scoped lang='less'>

</style>
